<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        li {
            width: 200px;
            background-color: orange;
        }
        li a {
            float: right;
            color:green;
        }
    </style>
</head>
<body>
    <textarea name="" id="" cols="30" rows="10"></textarea>
    <button>发布</button>
    <ul>
        <li>test</li>
    </ul>
</body>
<script>
    var btn = document.querySelector('button')
    var content = btn.previousElementSibling
    var show = btn.nextElementSibling
    btn.onclick = function(){
        //1.创建一个li
        if (content.value == '') {
            alert('请输入内容！')
        }else {
            var li = document.createElement('li')
        // 2.将内容放置在新的li中
            li.innerHTML = content.value + "<a href='javascript:;'>删除</a>"
            show.insertBefore(li,show.children[0])
            content.value = ''
            var as = document.querySelectorAll('a')
            for (var i = 0;i<as.length;i++) {
                as[i].onclick = function(){
                    show.removeChild(this.parentNode)
                }
            }
        }      
    }
</script>
</html>